<?php
class Article extends AppModel {
	public $name = 'Article';
	
	/* public $belongsTo = array(
        'Hero' => array(
        'className' => 'Hero',
        'foreignKey' => 'hero_id'
        ));   */
	
		
	function getListArticles(){
		return $this->find('all');
	}

	function getArticleById($id){
		return $this->find('first', array(
			'conditions' => array(
				'id'=> $id
			)
		));
	}
	function addNumberOfRead($id){
		$data =  $this->find('first', array(
			'conditions' => array(
				'id'=> $id
			)
		));
		$data['Article']['number_of_read'] += 1;
		return $this->save($data);
	}
	function countNumberOfRead($id){
		return  $this->find('count', array(
			'conditions' => array(
				'id'=> $id
			)
		));
	}
	function getListArticlesByHeroId($id){
		 return $this->find('all', array(
			'conditions' => array(
				'hero_id'=> $id
			)
		));
	}
	function getArticlesByName($name){
		return $this->find('all',array(
			'conditions' => array(
				'title like' => '%'.$name.'%'
			)
		));
	}
}